*/
-#include "defs.h"
#include "discard.h"
-#include <cstdlib>
-// Can't use QRegularExpression because Linux won't get Qt 5 for years.
-#include <QRegExp>
-#include <cstdio>
-#include <cstdlib>
+
+#include <QDebug> // for QDebug
+#include <QRegularExpression> // for QRegularExpression, QRegularExpression::CaseInsensitiveOption, QRegularExpressionMatch
+
+#include <cstdlib> // for atoi, atof
+
+#include "defs.h" // for Waypoint, fatal, route_del_wpt, route_disp_all, track_del_wpt, track_disp_all, waypt_del, waypt_disp_all, route_head, rtedata, trkdata, wptdata, fix_none, fix_unknown
+#include "src/core/logging.h" // for FatalMsg
+
#if FILTERS_ENABLED
del = 1;
}
- if (nameopt && name_regex.indexIn(waypointp->shortname) >= 0) {
+ if (nameopt && name_regex.match(waypointp->shortname).hasMatch()) {
del = 1;
}
- if (descopt && desc_regex.indexIn(waypointp->description) >= 0) {
+ if (descopt && desc_regex.match(waypointp->description).hasMatch()) {
del = 1;
}
- if (cmtopt && cmt_regex.indexIn(waypointp->notes) >= 0) {
+ if (cmtopt && cmt_regex.match(waypointp->notes).hasMatch()) {
del = 1;
}
- if (iconopt && icon_regex.indexIn(waypointp->icon_descr) >= 0) {
+ if (iconopt && icon_regex.match(waypointp->icon_descr).hasMatch()) {
del = 1;
}
}
+QRegularExpression DiscardFilter::generateRegExp(const QString& glob_pattern)
+{
+ QRegularExpression regex;
+ regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
+ QString pattern = QRegularExpression::wildcardToRegularExpression(glob_pattern);
+ // un-anchor the pattern, we allow partial matches.
+ if (pattern.startsWith("\\A") && pattern.endsWith("\\z")) {
+ pattern = pattern.mid(2,pattern.size()-4);
+ }
+ regex.setPattern(pattern);
+ return regex;
+}
+
void DiscardFilter::init()
{
if (hdopopt) {
}
if (nameopt) {
- name_regex.setCaseSensitivity(Qt::CaseInsensitive);
- name_regex.setPatternSyntax(QRegExp::WildcardUnix);
- name_regex.setPattern(nameopt);
+ name_regex = generateRegExp(nameopt);
+ if (!name_regex.isValid()) {
+ fatal(FatalMsg() << "discard: matchname option is an invalid expression.");
+ }
}
if (descopt) {
- desc_regex.setCaseSensitivity(Qt::CaseInsensitive);
- desc_regex.setPatternSyntax(QRegExp::WildcardUnix);
- desc_regex.setPattern(descopt);
+ desc_regex = generateRegExp(descopt);
+ if (!desc_regex.isValid()) {
+ fatal(FatalMsg() << "discard: matchdesc option is an invalid expression.");
+ }
}
if (cmtopt) {
- cmt_regex.setCaseSensitivity(Qt::CaseInsensitive);
- cmt_regex.setPatternSyntax(QRegExp::WildcardUnix);
- cmt_regex.setPattern(cmtopt);
+ cmt_regex = generateRegExp(cmtopt);
+ if (!cmt_regex.isValid()) {
+ fatal(FatalMsg() << "discard: matchcmt option is an invalid expression.");
+ }
}
if (iconopt) {
- icon_regex.setCaseSensitivity(Qt::CaseInsensitive);
- icon_regex.setPatternSyntax(QRegExp::WildcardUnix);
- icon_regex.setPattern(iconopt);
+ icon_regex = generateRegExp(iconopt);
+ if (!icon_regex.isValid()) {
+ fatal(FatalMsg() << "discard: matchicon option is an invalid expression.");
+ }
}
}
#ifndef DISCARD_H_INCLUDED_
#define DISCARD_H_INCLUDED_
-// Can't use QRegularExpression because Linux won't get Qt 5 for years.
-#include <QRegExp> // for QRegExp
-#include <QVector> // for QVector
+#include <QRegularExpression> // for QRegularExpression
+#include <QString> // for QString
+#include <QVector> // for QVector
-#include "defs.h" // for ARG_NOMINMAX, ARGTYPE_BEGIN_REQ, ARGTYPE_S...
-#include "filter.h" // for Filter
+#include "defs.h" // for arglist_t, ARG_NOMINMAX, ARGTYPE_BEGIN_REQ, ARGTYPE_STRING, ARGTYPE_BOOL, ARGTYPE_INT, ARGTYPE_FLOAT, route_head, ARGTYPE_END_REQ, Waypoint, gpsdata_type
+#include "filter.h" // for Filter
#if FILTERS_ENABLED
class DiscardFilter:public Filter
void init() override;
void process() override;
+private:
+ QRegularExpression generateRegExp(const QString& glob_pattern);
+
private:
char* hdopopt = nullptr;
char* vdopopt = nullptr;
char* eleminopt = nullptr;
char* elemaxopt = nullptr;
char* nameopt = nullptr;
- QRegExp name_regex;
+ QRegularExpression name_regex;
char* descopt = nullptr;
- QRegExp desc_regex;
+ QRegularExpression desc_regex;
char* cmtopt = nullptr;
- QRegExp cmt_regex;
+ QRegularExpression cmt_regex;
char* iconopt = nullptr;
- QRegExp icon_regex;
+ QRegularExpression icon_regex;
double hdopf{};
double vdopf{};
#include <QChar> // for QChar
#include <QDate> // for QDate
#include <QDateTime> // for QDateTime
-#ifdef TRACKF_DBG
#include <QDebug>
-#endif
#include <QList> // for QList<>::iterator, QList, QList<>::const_iterator
-#include <QRegExp> // for QRegExp, QRegExp::WildcardUnix
#include <QRegularExpression> // for QRegularExpression, QRegularExpression::CaseInsensitiveOption, QRegularExpression::PatternOptions
#include <QRegularExpressionMatch> // for QRegularExpressionMatch
#include <QString> // for QString
#include "grtcirc.h" // for RAD, gcdist, radtometers, heading_true_degrees
#include "src/core/datetime.h" // for DateTime
+#include "src/core/logging.h" // for FatalMsg
#if FILTERS_ENABLED || MINIMAL_FILTERS
}
if (opt_name != nullptr) {
- if (!QRegExp(opt_name, Qt::CaseInsensitive, QRegExp::WildcardUnix).exactMatch(track->rte_name)) {
+ QRegularExpression regex(QRegularExpression::wildcardToRegularExpression(opt_name),
+ QRegularExpression::CaseInsensitiveOption);
+ if (!regex.isValid()) {
+ fatal(FatalMsg() << "track: name option is an invalid expression.");
+ }
+ if (!regex.match(track->rte_name).hasMatch()) {
foreach (Waypoint* wpt, track->waypoint_list) {
track_del_wpt(const_cast<route_head*>(track), wpt);
delete wpt;
#ifndef TRACKFILTER_H_INCLUDED_
#define TRACKFILTER_H_INCLUDED_
-#include <QDateTime> // for QDateTime
-#include <QList> // for QList
-#include <QVector> // for QVector
-#include <QtGlobal> // for qint64
-
-#include "defs.h" // for ARG_NOMINMAX, route_head (ptr only), ARG...
-#include "filter.h" // for Filter
+#include <QDateTime> // for QDateTime
+#include <QList> // for QList
+#include <QVector> // for QVector
+#include <QtGlobal> // for qint64
+
+#include "defs.h" // for ARG_NOMINMAX, route_head (ptr only), ARG...
+#include "filter.h" // for Filter
+#include "src/core/datetime.h" // for DateTime
#if FILTERS_ENABLED || MINIMAL_FILTERS
long IDs that between (and including) GC1000 and GC2FFF, you could use
</para>
<para><userinput>
-gpsbabel -i geo -f geocaching.loc -x discard,matchname=GC[1-2]...
+gpsbabel -i geo -f geocaching.loc -x discard,matchname=GC[1-2]???
</userinput>
to discard all GCs followed by exactly three characters.
</para>